#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Reflection;
using System.Collections.Generic;

using CreamX.Framework.Game;
using Microsoft.Xna.Framework.Net;

#endregion

namespace CreamX.Framework.GameState.Screens
{

    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    public class MainMenuScreen : MenuScreen
    {
        GameScreen _loadedScreen;
        #region Initialization


        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen()
            : base("Main Menu")
        {
            //// Create our menu entries.
            //MenuEntry singlePlayerMenuEntry = new MenuEntry(Resources.SinglePlayer);
            //MenuEntry liveMenuEntry = new MenuEntry(Resources.PlayerMatch);
            //MenuEntry systemLinkMenuEntry = new MenuEntry(Resources.SystemLink);
            //MenuEntry exitMenuEntry = new MenuEntry(Resources.Exit);

            //// Hook up menu event handlers.
            //singlePlayerMenuEntry.Selected += SinglePlayerMenuEntrySelected;
            //liveMenuEntry.Selected += LiveMenuEntrySelected;
            //systemLinkMenuEntry.Selected += SystemLinkMenuEntrySelected;
            //exitMenuEntry.Selected += OnCancel;

            //// Add entries to the menu.
            //MenuEntries.Add(singlePlayerMenuEntry);
            //MenuEntries.Add(liveMenuEntry);
            //MenuEntries.Add(systemLinkMenuEntry);
            //MenuEntries.Add(exitMenuEntry);
        }


        #endregion
        List<Type> ScreenTypes = new List<Type>();
        public void AddMenuEntry(Type screen, string display)
        {
            ScreenTypes.Add(screen);
            MenuEntry mnu = new MenuEntry(display);
            mnu.Selected += new EventHandler<EventArgs>(mnu_Selected);
            MenuEntries.Add(mnu);
        }
        public void AddMenuEntry(MenuEntry entry)
        {
            
            MenuEntries.Add(entry);
        }
        void mnu_Selected(object sender, EventArgs e)
        {
            int entryIndex = MenuEntries.IndexOf(sender as MenuEntry);
            Type __t = ScreenTypes[entryIndex];
            
            //Assembly __Asm=Assembly.GetCallingAssembly();
            //Assembly __Asm1=Assembly.GetExecutingAssembly();
            if (__t == null)
            {
            }
            else
            {
                _loadedScreen = (GameScreen)CreamXGame.Instance._callingAssembly.CreateInstance(__t.ToString());
                //Assembly __a= Assembly.Load(Assembly.GetCallingAssembly().
                if (_loadedScreen != null)
                {
                    if (_loadedScreen is GameplayScreen)
                    {
                        //LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
                        LoadingScreen.Load(ScreenManager, true, new GameScreen[] { _loadedScreen });
                    }
                    else
                    {
                        ScreenManager.AddScreen(_loadedScreen);
                    }
                }
            }
            /*    case 0:
                    // Play the game.
                    LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
                    break;
               //            case 1:
                    // Go to the options screen.
                    ScreenManager.AddScreen(ScreenManager.GetOptionsScreen());
                    break;


            }*/
        }
        internal void AddMenuEntry(string name)
        {
            ScreenTypes.Add(null);
            MenuEntry mnu = new MenuEntry(name);
            mnu.Selected += new EventHandler<EventArgs>(mnu_Selected);
            MenuEntries.Add(mnu);
        }
        #region Handle Input


        /// <summary>
        /// Event handler for when the Single Player menu entry is selected.
        /// </summary>
        void SinglePlayerMenuEntrySelected(object sender, EventArgs e)
        {
            //LoadingScreen.Load(ScreenManager, true, new GameplayScreen(null));
        }


        /// <summary>
        /// Event handler for when the Live menu entry is selected.
        /// </summary>
        void LiveMenuEntrySelected(object sender, EventArgs e)
        {
            //CreateOrFindSession(NetworkSessionType.PlayerMatch);
        }


        /// <summary>
        /// Event handler for when the System Link menu entry is selected.
        /// </summary>
        void SystemLinkMenuEntrySelected(object sender, EventArgs e)
        {
            //CreateOrFindSession(NetworkSessionType.SystemLink);
        }


        /// <summary>
        /// Helper method shared by the Live and System Link menu event handlers.
        /// </summary>
        void CreateOrFindSession(NetworkSessionType sessionType)
        {
            //// First, we need to make sure a suitable gamer profile is signed in.
            //ProfileSignInScreen profileSignIn = new ProfileSignInScreen(sessionType);

            //// Hook up an event so once the ProfileSignInScreen is happy,
            //// it will activate the CreateOrFindSessionScreen.
            //profileSignIn.ProfileSignedIn += delegate
            //{
            //    ScreenManager.AddScreen(new CreateOrFindSessionScreen(sessionType));
            //};

            //// Activate the ProfileSignInScreen.
            //ScreenManager.AddScreen(profileSignIn);
        }


        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel()
        {
            //MessageBoxScreen confirmExitMessageBox =
            //                        new MessageBoxScreen(Resources.ConfirmExitSample);

            //confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            //ScreenManager.AddScreen(confirmExitMessageBox);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to exit" message box.
        /// </summary>
        void ConfirmExitMessageBoxAccepted(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }


        #endregion
    }
    ///// <summary>
    ///// The main menu screen is the first thing displayed when the game starts up.
    ///// </summary>
    //public class MainMenuScreen : MenuScreen
    //{
    //    #region Initialization


    //    /// <summary>
    //    /// Constructor fills in the menu contents.
    //    /// </summary>
    //    public MainMenuScreen()
    //    {
            
            
    //    }
    //    List<Type> ScreenTypes = new List<Type>();
    //    public void AddMenuEntry(Type screen, string display)
    //    {
    //        ScreenTypes.Add(screen);
    //        MenuEntries.Add(display);
    //    }
    //    internal void AddMenuEntry(string name)
    //    {
    //        ScreenTypes.Add(null);
    //        MenuEntries.Add(name);
    //    }
    //    #endregion

    //    #region Handle Input
    //    ScreenManager.GameScreen _loadedScreen;
    //    int _selectedEntry = 0;
    //    /// <summary>
    //    /// Responds to user menu selections.
    //    /// </summary>
    //    protected override void OnSelectEntry(int entryIndex)
    //    {
    //        _selectedEntry = entryIndex;
    //        if (entryIndex == MenuEntries.Count - 1)
    //        {
    //            OnCancel();
    //            return;
    //        }
    //        Type __t=ScreenTypes[entryIndex];
    //        //Assembly __Asm=Assembly.GetCallingAssembly();
    //        //Assembly __Asm1=Assembly.GetExecutingAssembly();
    //        if (__t == null)
    //        {
    //        }
    //        else
    //        {
    //            _loadedScreen = (GameScreen)CreamXGame.Instance._callingAssembly.CreateInstance(__t.ToString());
    //            //Assembly __a= Assembly.Load(Assembly.GetCallingAssembly().
    //            if (_loadedScreen != null)
    //            {
    //                if (_loadedScreen is GameplayScreen)
    //                {
    //                    LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
    //                }
    //                else
    //                {
    //                    ScreenManager.AddScreen(_loadedScreen as ScreenManager.GameScreen);
    //                }
    //            }
    //        }
    //        /*    case 0:
    //                // Play the game.
    //                LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
    //                break;

    //            case 1:
    //                // Go to the options screen.
    //                ScreenManager.AddScreen(ScreenManager.GetOptionsScreen());
    //                break;

                
    //        }*/
    //    }
    //    public override void LoadContent()
    //    {
            
    //        base.LoadContent();
            
    //    }
        

    //    /// <summary>
    //    /// When the user cancels the main menu, ask if they want to exit the sample.
    //    /// </summary>
    //    protected override void OnCancel()
    //    {
    //        const string message = "Are you sure you want to exit this sample?";

    //        MessageBoxScreen messageBox = new MessageBoxScreen(message);

    //        messageBox.Accepted += ExitMessageBoxAccepted;

    //        ScreenManager.AddScreen(messageBox);
    //    }


    //    /// <summary>
    //    /// Event handler for when the user selects ok on the "are you sure
    //    /// you want to exit" message box.
    //    /// </summary>
    //    void ExitMessageBoxAccepted(object sender, EventArgs e)
    //    {
    //        ScreenManager.Game.Exit();
    //    }


    //    /// <summary>
    //    /// Loading screen callback for activating the gameplay screen.
    //    /// </summary>
    //    void LoadGameplayScreen(object sender, EventArgs e)
    //    {
    //        ScreenManager.AddScreen(_loadedScreen);
    //    }


    //    #endregion

        
    //}
}
